home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Archives / GNU / GNUPLOTsrc.lha / term / imagen.trm < prev    next >
Encoding:
Text File  |  1996-01-22  |  21.1 KB  |  877 lines

  1. /*
  2.  * $Id: imagen.trm,v 1.11 1995/12/20 21:47:56 drd Exp $
  3.  */
  4.  
  5. /* GNUPLOT - imagen.trm */
  6. /*
  7.  * Copyright (C) 1990   
  8.  *
  9.  * Permission to use, copy, and distribute this software and its
  10.  * documentation for any purpose with or without fee is hereby granted, 
  11.  * provided that the above copyright notice appear in all copies and 
  12.  * that both that copyright notice and this permission notice appear 
  13.  * in supporting documentation.
  14.  *
  15.  * Permission to modify the software is granted, but not the right to
  16.  * distribute the modified code.  Modifications are to be distributed 
  17.  * as patches to released version.
  18.  *  
  19.  * This software  is provided "as is" without express or implied warranty.
  20.  * 
  21.  * This file is included by ../term.c.
  22.  *
  23.  * This terminal driver supports:
  24.  *   Imagen laser printers
  25.  *
  26.  * AUTHORS
  27.  *   Paul E. McKenney, David Kotz
  28.  *   Rewritten/extended by:
  29.  *    Hans Olav Eggestad
  30.  * send your comments or suggestions to (info-gnuplot@dartmouth.edu).
  31.  * 
  32.  */
  33.  
  34. /*
  35.  * Original for direct Imagen output (but retaining many of the
  36.  * LaTeX extensions) by Paul E. McKenney, 1989.
  37.  * Further modified by David Kotz to fit into gnuplot 2.0.
  38.  * Information Science and Technology Division, SRI International,
  39.  * 333 Ravenswood Ave, Menlo Park, CA 94025.
  40.  * Mail to mckenney@sri.com.
  41.  */
  42. /*
  43.  * adapted to the new terminal layout by Stefan Bodewig (Dec. 1995)
  44.  */
  45.  
  46. #ifndef GOT_DRIVER_H
  47. #include "driver.h"
  48. #endif
  49.  
  50. #ifdef TERM_REGISTER
  51. register_term(imagen)
  52. #endif
  53.  
  54. #ifdef TERM_PROTO
  55. TERM_PUBLIC void IMAGEN_init __P((void));
  56. TERM_PUBLIC void IMAGEN_graphics __P((void));
  57. TERM_PUBLIC void IMAGEN_options __P((void));
  58. TERM_PUBLIC void IMAGEN_text __P((void));
  59. TERM_PUBLIC void IMAGEN_linetype __P((int lt));
  60. TERM_PUBLIC void IMAGEN_move __P((unsigned int x, unsigned int y));
  61. TERM_PUBLIC void IMAGEN_vector __P((unsigned int ux, unsigned int uy));
  62. TERM_PUBLIC int IMAGEN_text_angle __P((int angle));
  63. TERM_PUBLIC int IMAGEN_justify_text __P((enum JUSTIFY mode));
  64. TERM_PUBLIC void IMAGEN_put_text __P((unsigned int x, unsigned int y, char str[]));
  65. TERM_PUBLIC void IMAGEN_reset __P((void));
  66. #define IMAGEN_PTS_PER_INCH (300)
  67. #define IMAGEN_XMAX (IMAGEN_PTS_PER_INCH * 11) /* 10.0 inches */
  68. #define IMAGEN_YMAX (IMAGEN_PTS_PER_INCH * 78 / 10) /* 7.5 inches */
  69. #define IMAGEN_HTIC (20)
  70. #define IMAGEN_VTIC (20)
  71. #define IMAGEN_VCHAR (IMAGEN_FONTSIZE*5)
  72. #define IMAGEN_HCHAR (IMAGEN_VCHAR/2)
  73. #endif /* TERM_PROTO */
  74.  
  75. #ifndef TERM_PROTO_ONLY
  76. #ifdef TERM_BODY
  77.  
  78. void IM_page __P((void));
  79. void IMAGEN_draw_path __P((void));
  80. static void IMAGEN_setpos __P((int ux, int uy));
  81. static unsigned char * IMAGEN_cvts __P((unsigned char *str, int *width, int *height));
  82. static void IMAGEN_putwd __P((unsigned int w));
  83. static void IMAGEN_createfamily __P((char *c, int sz));
  84. static void IMAGEN_setfont __P((int sz));
  85. void IMP_set_draw_pattern __P((int pattern, int sz));
  86. void IMAGEN_mapsinit __P((void));
  87. void IMAGEN_createmap __P((int name, unsigned short *map));
  88.  
  89.  
  90. /* #ifndef __malloc_h
  91. #include <malloc.h>
  92. #endif
  93. */
  94. #include "impcodes.h"
  95.  
  96. #define IMAGEN_A4_H  (IMAGEN_PTS_PER_INCH * 83 / 10) /* default is landscape */
  97. #define IMAGEN_A4_W  (IMAGEN_PTS_PER_INCH * 116 / 10)
  98.  
  99. static int IMAGEN_Xmax = IMAGEN_XMAX;  /* width in current orientation */
  100. static int IMAGEN_Ymax = IMAGEN_YMAX;
  101.  
  102. #define IMAGEN_FONTSIZE 12
  103. #define IMAGEN_FONT "cour"
  104.  
  105.  
  106. unsigned short IMP_gmap[127];
  107. unsigned char IMP_chmap[256];
  108.  
  109. static int IMAGEN_page_h  = IMAGEN_A4_H;
  110. static int IMAGEN_page_w = IMAGEN_A4_W;
  111. static int IM_win_horiz = 1;
  112. static int IM_win_verti = 1;
  113. static int IM_plot_nr = 0;
  114.  
  115. static int IMAGEN_fontsize = IMAGEN_FONTSIZE;
  116. static int IMAGEN_familytable[36];
  117. static int IMAGEN_orgX;        /* absolute-pixel-ORIgin of graph page.    */
  118. static int IMAGEN_orgY;
  119. static int IMAGEN_orgx;        /* absolute-pixel-ORIgin of current graph. */
  120. static int IMAGEN_orgy;
  121. static int IMAGEN_posx;        /* current drawing position (lines).    */
  122. static int IMAGEN_posy;
  123. /* static int IMAGEN_inplot; */
  124. static int IMAGEN_xmax = IMAGEN_XMAX;    /* width of graph in pixels.    */
  125. static int IMAGEN_ymax = IMAGEN_YMAX;    /* height of graph in pixels.    */
  126. static int IMAGEN_winx = IMAGEN_XMAX;    /* width of window in pixels.    */
  127. static int IMAGEN_winy = IMAGEN_YMAX;    /* height of window in pixels.    */
  128. static int IMAGEN_hchar;    /* Height of CHAR in current font.    */
  129. static int IMAGEN_wchar;    /* Width of CHAR in current font.    */
  130. static int IMAGEN_blofs;    /* BaseLine OFfSet from bounding box.    */
  131. static int IMAGEN_angle = -1;    /* 0 for horizontal text, 1 for vertical */
  132. static int IMAGEN_portrait;    /* 0 for landscape */
  133. static enum JUSTIFY IMAGEN_justify = LEFT; /* left/center/right */
  134.  
  135. /* static IMAGEN_seq_pos;        /* position in sequence */
  136. #define STOREPATH 100
  137. unsigned int IM_xvector[STOREPATH];    /* draw path vector of x values */
  138. unsigned int IM_yvector[STOREPATH];    /* draw path vector of y values */
  139. unsigned int IM_veclen;        /* length of allocated path vector */
  140. unsigned int IM_vecpos = 0;        /* current pos in vector */
  141.  
  142. static void IMAGEN_putwd();
  143. static void IMAGEN_createfamily();
  144. static void IMAGEN_setfont();
  145. static void IMAGEN_setpos();
  146. void IMP_set_draw_pattern();
  147. static unsigned char *IMAGEN_cvts();
  148.  
  149. /* char IMPdrpattern[10][10] = { {0}, {30,10,0}, {0}, {10,30,0}, {2,20,0}, 
  150.     {20,10,0}, {30,20,10,20,0}, {30,20,4,10,10,10,4,20,0}, {40,20,0}, {30,15,4,15,0}
  151. };
  152. */
  153.  
  154. char IMPdrpattern[10][10] = { 
  155. /* -2 */ {0}, 
  156. /* -1 */ {1,8,0}, 
  157. /*  0 */ {0}, 
  158. /*  1 */ {16,4,0}, 
  159. /*  2 */ {3,8,0}, 
  160. /*  3 */ {8,8,0}, 
  161. /*  4 */ {16,6,3,6,0}, 
  162. /*  5 */ {16,6,8,6,0}, 
  163. /*  6 */ {16,4,1,4,8,4,1,4,0}, 
  164. /*  7 */ {16,4,1,8,1,4,0}
  165. };
  166.  
  167. TERM_PUBLIC void IMAGEN_init()
  168. {
  169.     register struct termentry *t = term;
  170.  
  171.     /* char font[10];    */        /* font name */
  172.  
  173.     IMAGEN_posx = IMAGEN_posy = 0;
  174.  
  175.     IMAGEN_orgX = (IMAGEN_page_w - IMAGEN_Xmax) / 2;
  176.     IMAGEN_orgY = (IMAGEN_page_h - IMAGEN_Ymax) / 2;
  177.  
  178.     IMAGEN_xmax = IMAGEN_winx = (int)(IMAGEN_Xmax / IM_win_horiz);
  179.     IMAGEN_ymax = IMAGEN_winy = (int)(IMAGEN_Ymax / IM_win_verti);
  180.  
  181.     t->xmax = (unsigned int)(IMAGEN_xmax);
  182.     t->ymax = (unsigned int)(IMAGEN_ymax);
  183.  
  184.     fputs("@document(language impress, paper a4)", outfile);
  185.  
  186.     if (IMAGEN_portrait) {
  187.         putc(imP_SET_ABS_V, outfile);
  188.         IMAGEN_putwd(3520);
  189.     }
  190.     putc(imP_SET_HV_SYSTEM, outfile);
  191.     putc(((IMAGEN_portrait?3:0)<<5)|(3<<3)|(IMAGEN_portrait?0:5), outfile);
  192.  
  193.     /* sprintf(font, "cour%02d", IMAGEN_FONTSIZE); */
  194.     IMAGEN_mapsinit();
  195.     IMAGEN_createmap(1,IMP_gmap);
  196.     /* IMAGEN_createfamily(font, IMAGEN_FONTSIZE); */
  197.     IMAGEN_setfont(IMAGEN_fontsize);
  198.  
  199.     IMAGEN_text_angle(0);
  200.  
  201.     putc(imP_SET_ABS_H, outfile);
  202.     IMAGEN_putwd(0);
  203.     putc(imP_SET_ABS_V, outfile);
  204.     IMAGEN_putwd(0);
  205.  
  206.     IMAGEN_linetype(-1);
  207.     /*
  208.     if ((IM_xvector = (unsigned int *) malloc(STOREPATH*sizeof(int))) == NULL) {
  209.     fprintf (stderr,"Imagendriver: Unable to allocate memory for draw path\n");
  210.     exit(1);
  211.     }
  212.     if ((IM_yvector = (unsigned int *) malloc(STOREPATH*sizeof(int))) == NULL) {
  213.     fprintf (stderr,"Imagendriver: Unable to allocate memory for draw path\n");
  214.     exit(1);
  215.     }
  216.     */
  217.     IM_veclen = STOREPATH;
  218.     IM_vecpos = 0;
  219. }
  220.  
  221. void IM_page()
  222. {
  223.     if ( IM_vecpos ) {
  224.     /* fprintf(stderr,"graphics, draw path\n"); */
  225.     IMAGEN_draw_path();
  226.     }
  227.     putc(imP_ENDPAGE, outfile);
  228. }
  229.  
  230. TERM_PUBLIC void IMAGEN_graphics()
  231. {
  232.     int tmpx, tmpy;
  233. /*    int xoff, yoff; */
  234.  
  235.     if ( IM_vecpos ) {
  236.     /* fprintf(stderr,"graphics, draw path\n"); */
  237.     IMAGEN_draw_path();
  238.     }
  239.     if ( IM_plot_nr >= ( IM_win_horiz * IM_win_verti )) {
  240.     IM_page();
  241.     IM_plot_nr = 0;
  242.     }
  243.     IM_plot_nr++;
  244.     tmpx = IMAGEN_orgX + ((IM_plot_nr - 1) % IM_win_horiz) * IMAGEN_winx;
  245.     tmpy = IMAGEN_orgY + ((IM_win_verti - 1) - (int)((IM_plot_nr - 1) / IM_win_horiz)) * IMAGEN_winy;
  246.     IMAGEN_orgx = tmpx + (int)((IMAGEN_winx - IMAGEN_xmax)/2);
  247.     IMAGEN_orgy = tmpy + (int)((IMAGEN_winy - IMAGEN_ymax)/2);
  248. }
  249.  
  250. TERM_PUBLIC void IMAGEN_options()
  251. {
  252.     struct value a;
  253.  
  254.     while (!END_OF_COMMAND) {
  255.         if (almost_equals(c_token,"p$ortrait")) {
  256.             IMAGEN_portrait=TRUE;
  257.             IMAGEN_page_h = IMAGEN_A4_W;
  258.             IMAGEN_page_w = IMAGEN_A4_H;
  259.             IMAGEN_Xmax = IMAGEN_YMAX;
  260.             IMAGEN_Ymax = IMAGEN_XMAX;
  261.             c_token++;
  262.         }
  263.         else if (almost_equals(c_token,"l$andscape")) {
  264.             IMAGEN_portrait=FALSE;
  265.             c_token++;
  266.         } else if (equals(c_token,"[")) { /* windows spesified */
  267.             c_token++;
  268.             /* if (IM_plot_nr>1) */
  269.             if (equals(c_token,"]")) {
  270.                 IM_page();
  271.                 c_token++;
  272.                 continue;
  273.             }
  274.             if (END_OF_COMMAND) {
  275.                     int_error("no. windows: [horizontal,vertical] expected",c_token);
  276.             } else if (!equals(c_token,","))  {
  277.                 IM_win_horiz = (int)real(const_express(&a));
  278.             }    
  279.             if (!equals(c_token,","))
  280.                 int_error("',' expected",c_token);
  281.             c_token++;
  282.             if (!equals(c_token,"]")) {
  283.                 IM_win_verti = (int)real(const_express(&a));
  284.              }
  285.             if (!equals(c_token,"]"))
  286.                   int_error("expecting ']'",c_token);
  287.             c_token++;
  288.         } else {
  289.             /* We have font size specified */
  290.             IMAGEN_fontsize = (int)real(const_express(&a));
  291.             if ( IMAGEN_fontsize < 8 ) 
  292.                 IMAGEN_fontsize = 8;
  293.             if ( IMAGEN_fontsize > 15 ) 
  294.                 IMAGEN_fontsize = 15;
  295.         }
  296.     }
  297.     sprintf(term_options,"%d %s [%1d,%1d]",IMAGEN_fontsize,(IMAGEN_portrait)?"portrait":"landscape",IM_win_horiz,IM_win_verti);
  298. }
  299.  
  300.  
  301. TERM_PUBLIC void IMAGEN_text()
  302. {
  303. }
  304.  
  305.  
  306. #define DRAW_PATTERNS 6
  307.  
  308.  
  309. TERM_PUBLIC void IMAGEN_linetype(lt)
  310. int lt;
  311. {
  312.     static int lastlinetype = -10;
  313.     int pen/*, pattern*/ ;
  314.  
  315.     if ( IM_vecpos ) {
  316.     /* fprintf(stderr,"move, draw path\n"); */
  317.     IMAGEN_draw_path();
  318.     }
  319. /* -2: axis
  320.    -1: border
  321.     0: arrow
  322.     1-7: graph
  323. */
  324.     if (lt == -2) {
  325.         pen = 4;
  326.     } else {
  327.         pen = (int) (lt/8)*2;
  328.         if ( pen <= 0 ) pen = 1;
  329.     }
  330.     lt  = (lt % 8) +2;
  331.  
  332.     if (lastlinetype == lt)
  333.      return;
  334.  
  335.     lastlinetype = lt;    
  336.  
  337.     putc(imP_SET_PEN, outfile);
  338.     putc(pen, outfile);
  339.     IMP_set_draw_pattern(lt,pen);
  340. }
  341.  
  342.  
  343. TERM_PUBLIC void IMAGEN_move(x,y)
  344.     unsigned int x,y;
  345. {
  346.     if ( IM_vecpos ) {
  347.     /* fprintf(stderr,"move, draw path\n"); */
  348.     IMAGEN_draw_path();
  349.     }
  350.     IM_xvector[0] = x + IMAGEN_orgx;
  351.     IM_yvector[0] = y + IMAGEN_orgy;
  352.     /* fprintf(stderr,"Ny vector: startpos: %1d %1d\n",IM_xvector[0],IM_yvector[0]); */
  353.     IM_vecpos = 1;
  354.     /* 
  355.     IMAGEN_posx = x;
  356.     IMAGEN_posy = y;
  357.     */
  358. }
  359.  
  360. TERM_PUBLIC void IMAGEN_vector(ux,uy)
  361.     unsigned int ux,uy;
  362. {
  363.     /* void IMAGEN_draw_path(); */
  364.  
  365.         /* Store path. */
  366.     IM_xvector[IM_vecpos] = ux + IMAGEN_orgx;
  367.     IM_yvector[IM_vecpos] = uy + IMAGEN_orgy;
  368.     /* fprintf(stderr,"Ny node: nr: %1d; %1d %1d\n",IM_vecpos,IM_xvector[IM_vecpos],IM_yvector[IM_vecpos]);  */
  369.     IM_vecpos ++;
  370.     if ( IM_vecpos >= IM_veclen ) {
  371.         IMAGEN_draw_path();
  372.         IM_xvector[0] = ux + IMAGEN_orgx;
  373.         IM_yvector[0] = uy + IMAGEN_orgy;
  374.         IM_vecpos = 1;
  375.     }
  376. }
  377.  
  378. void IMAGEN_draw_path()
  379. {
  380. /*    unsigned int pos; */
  381.     register int i;
  382.  
  383.     putc(imP_CREATE_PATH, outfile);
  384.     IMAGEN_putwd(IM_vecpos);
  385.     for (i=0;i<IM_vecpos;i++) {
  386.     /*
  387.         IMAGEN_putwd(IM_xvector[i] + IMAGEN_orgx);
  388.         IMAGEN_putwd(IM_yvector[i] + IMAGEN_orgy);
  389.     */
  390.         IMAGEN_putwd(IM_xvector[i]);
  391.         IMAGEN_putwd(IM_yvector[i]);
  392.     }
  393.     IM_vecpos = 0;
  394.     /* Draw path with black pen. */
  395.  
  396.     putc(imP_DRAW_PATH, outfile);
  397.     putc(15, outfile);
  398.  
  399.     /* Set current position to end of line. */
  400.  
  401.     /* IMAGEN_move(ux, uy); */
  402. }
  403.  
  404. static void
  405. IMAGEN_setpos(ux, uy)
  406.     int ux,uy;
  407. {
  408.     /* Set x and y position (for text), also set beginning-of-line. */
  409.  
  410.     putc(imP_SET_ABS_H, outfile);
  411.     IMAGEN_putwd(ux + IMAGEN_orgx);
  412.     putc(imP_SET_ABS_V, outfile);
  413.     IMAGEN_putwd(uy + IMAGEN_orgy);
  414.     putc(imP_SET_BOL, outfile);
  415.     if (IMAGEN_angle == 1)
  416.      IMAGEN_putwd(uy + IMAGEN_orgx); /* vertical */
  417.     else
  418.      IMAGEN_putwd(ux + IMAGEN_orgx); /* horizontal */
  419. }
  420.  
  421. TERM_PUBLIC int IMAGEN_text_angle(angle)
  422.     int angle;
  423. {
  424.     
  425.     if ( IM_vecpos ) {
  426.     /* fprintf(stderr,"text_angle, draw path\n"); */
  427.     IMAGEN_draw_path();
  428.     }
  429.     if (IMAGEN_angle != angle) {
  430.        IMAGEN_angle = angle;    /* record for later use */
  431.        putc(imP_SET_ADV_DIRS, outfile);
  432.        putc(angle == 0 ? 0 : 7, outfile); /* 0=>horiz : 7=>vert */
  433.     }
  434.  
  435.     return(TRUE);
  436. }
  437.  
  438. TERM_PUBLIC int IMAGEN_justify_text(mode)
  439.     enum JUSTIFY mode;
  440. {
  441.     if ( IM_vecpos ) {
  442.     /* fprintf(stderr,"justify_text, draw path\n"); */
  443.     IMAGEN_draw_path();
  444.     }
  445.     IMAGEN_justify = mode;
  446.     return(TRUE);
  447. }
  448.  
  449. static unsigned char *
  450. IMAGEN_cvts(str, width, height)
  451.     unsigned char        *str;
  452.     int        *width;
  453.     int        *height;
  454. {
  455.     unsigned char        *cp1;
  456.     unsigned char        *cp2;
  457.     static unsigned char    *buf = NULL;
  458.     int        h;
  459.     int        maxw;
  460.     int        w;
  461.  
  462.     /* Free up old buffer, if there is one, get a new one.  Since    */
  463.     /* all transformations shorten the string, get a buffer that is    */
  464.     /* the same size as the input string.                */
  465.  
  466.     if (buf != NULL)
  467.      (void) free(buf);
  468.     buf = (unsigned char *)alloc(strlen((char *)str),"converted label string");
  469.  
  470.     /* Do the transformations. */
  471.  
  472.     cp1 = str;
  473.     cp2 = buf;
  474.     h = 1;
  475.     maxw = 0;
  476.     w = 0;
  477.     while (strlen((char *)cp1) > 0) {
  478.        switch (*cp1) {
  479.           case ' ' :        /* Space character. */
  480.             *cp2++ = imP_SP;
  481.             w++;
  482.             break;
  483.             
  484.             case  '\\' :    /* Escape sequence. */
  485.              if (*++cp1 == '\\') {
  486.                 /* Begin new line. */
  487.                 h++;
  488.                 if (w > maxw)
  489.                   maxw = w;
  490.                 w = 0;
  491.                 *cp2++ = '\n';
  492.                 /* *cp2++ = imP_CRLF; */
  493.                 break;
  494.              }
  495.             
  496.             /* Fall through to just copy next char out.    */
  497.             
  498.             default :
  499.              /* *cp2++ = *cp1; */
  500.              *cp2++ = IMP_chmap[*cp1];
  501.             w++;
  502.             break;
  503.         }
  504.        cp1++;
  505.     }
  506.     
  507.     *cp2++ = '\n';
  508.     *cp2 = '\0';
  509.     if (w > maxw)
  510.      maxw = w;
  511.     
  512.     if (height != NULL)
  513.      *height = IMAGEN_angle ?
  514.        IMAGEN_wchar * maxw :
  515.         IMAGEN_hchar * h;
  516.     if (width != NULL)
  517.      *width = IMAGEN_angle ?
  518.        IMAGEN_hchar * h :
  519.         IMAGEN_wchar * maxw;
  520.     return (buf);
  521. }
  522.  
  523. TERM_PUBLIC void IMAGEN_put_text(x, y, str)
  524.     unsigned int x,y;            /* reference point of string */
  525.     char str[];                /* the text */
  526. {
  527.     unsigned char *cvstr, *p;
  528.     int height;
  529.     int width;
  530.     int sx, sy;
  531.     
  532.     if ( IM_vecpos ) {
  533.     /* fprintf(stderr,"put_text, draw path\n"); */
  534.     IMAGEN_draw_path();
  535.     }
  536.  
  537.     cvstr = IMAGEN_cvts((unsigned char *)str, &width, &height);
  538.  
  539.     if (IMAGEN_angle) {        /* vertical */
  540.     /* x += IMAGEN_hchar; */
  541.        x -= width/2 - IMAGEN_hchar;
  542.       /* y -= height/2; */
  543.     } else                /* horizontal */
  544.      y += height/2 - IMAGEN_hchar;
  545.  
  546.     while ( (p=(unsigned char *)strchr((char *)cvstr,'\n' )) ){
  547.     *p = '\0';
  548.         sx = x;
  549.         sy = y;
  550.         if ( IMAGEN_angle )
  551.         sx = x - IMAGEN_blofs;
  552.         else
  553.         sy = y + IMAGEN_blofs;
  554.     
  555.         width = strlen((char *)cvstr)*IMAGEN_wchar;
  556.     
  557.         switch (IMAGEN_justify) {
  558.            case LEFT: 
  559.             break;
  560.            case CENTRE: 
  561.             if ( IMAGEN_angle ) {
  562.                 sy = y - width/2;
  563.             } else {
  564.                 sx = x - width/2;
  565.             }
  566.             break;
  567.             /*x -= width/2; break; */
  568.            case RIGHT: 
  569.             if ( IMAGEN_angle ) {
  570.                 sy = y - width;
  571.             } else {
  572.                 sx = x - width;
  573.             }
  574.             break;
  575.             /* x -= width; break; */
  576.         }
  577.  
  578.         IMAGEN_setpos(sx, sy);
  579.         fputs((char *)cvstr, outfile);
  580.     cvstr = ++p;
  581.     if (IMAGEN_angle) {     /* vertical */
  582.         x += IMAGEN_hchar;
  583.     } else {
  584.         y -= IMAGEN_hchar;
  585.     }
  586.  
  587.     }
  588. }
  589.  
  590. TERM_PUBLIC void IMAGEN_reset()
  591. {
  592.     if ( IM_vecpos ) {
  593.     /* fprintf(stderr,"reset, draw path\n"); */
  594.     IMAGEN_draw_path();
  595.     }
  596.     putc(imP_EOF, outfile);
  597. }
  598.  
  599. static void
  600. IMAGEN_putwd(w)
  601. unsigned int w;
  602. {
  603.     /* fprintf(stderr,"%1u\n",w); */
  604.     putc(w>>8, outfile);
  605.     putc(w, outfile);
  606. }
  607.  
  608. static void
  609. IMAGEN_createfamily(c, sz)
  610.     char        *c;
  611.     int        sz;
  612. {
  613.  
  614.     putc(imP_CREATE_FAMILY_TABLE, outfile);
  615.     putc(sz, outfile);
  616.     putc(1, outfile);
  617.     putc(1, outfile);
  618.     /* putc(0, outfile); */
  619.     fputs(c, outfile);
  620.     putc(0, outfile);
  621. }
  622.  
  623. static void
  624. IMAGEN_setfont(sz) 
  625.     int sz;
  626. {
  627.     char font[20];
  628.  
  629.     if ( ! IMAGEN_familytable[sz] ) {
  630.     sprintf(font,"%s%02d",IMAGEN_FONT,sz);
  631.     IMAGEN_createfamily(font, sz);
  632.         IMAGEN_familytable[sz] = sz;
  633.     }
  634.     IMAGEN_hchar = sz * 5;
  635.     IMAGEN_wchar = IMAGEN_hchar / 2;
  636.     IMAGEN_blofs = IMAGEN_hchar / 3;
  637.     term->v_char = IMAGEN_hchar;
  638.     term->h_char = IMAGEN_wchar;
  639.     putc(imP_SET_FAMILY, outfile);
  640.     putc(sz, outfile);
  641.     putc(imP_SET_SP, outfile);
  642.     IMAGEN_putwd(IMAGEN_wchar);
  643.     putc(imP_SET_IL, outfile);
  644.     IMAGEN_putwd(IMAGEN_hchar);
  645. }
  646.  
  647. void
  648. IMP_set_draw_pattern(pattern,sz)
  649. int sz, pattern;
  650. {
  651.     int i /*,j */ ;
  652.     putc(imP_SET_DRAW_PATTERN, outfile);
  653.     putc(0,outfile);
  654.     putc(imP_SET_DRAW_PATTERN, outfile);
  655.     /* if ( strlen(IMPdrpattern[pattern]) == 1 ) {
  656.         putc(type,outfile);
  657.         return;
  658.     } */ 
  659.     putc(strlen(IMPdrpattern[pattern]),outfile);
  660.     for ( i=0;i<strlen(IMPdrpattern[pattern]);i++) {
  661.         IMAGEN_putwd(IMPdrpattern[pattern][i]*sz);
  662.     }
  663. }
  664.  
  665.  
  666. void IMAGEN_mapsinit()
  667. {
  668.  
  669.     register int i /*, j */ ;
  670.  
  671.     for ( i=32;i<127;i++) {
  672.         IMP_gmap[i] = i;
  673.     }
  674.     IMP_gmap[1] = 225;
  675.     IMP_gmap[2]  = 233;
  676.     IMP_gmap[3] = 61736;
  677.     IMP_gmap[4] = 241;
  678.     IMP_gmap[5]  = 249;
  679.     IMP_gmap[6] = 61864;
  680.     IMP_gmap[7] = 162;
  681.     IMP_gmap[8] = 163;
  682.     IMP_gmap[9] = 164;
  683.     IMP_gmap[10] = 165;
  684.     IMP_gmap[11] = 167;
  685.     IMP_gmap[12] = 171;
  686.     IMP_gmap[13] = 182;
  687.     IMP_gmap[14] = 61346;
  688.     IMP_gmap[15] = 191;
  689.     IMP_gmap[16] = 187;
  690.     IMP_gmap[17] = 188;
  691.     IMP_gmap[18] = 189;
  692.     IMP_gmap[19] = 190;
  693.     IMP_gmap[20] = 210;
  694.     IMP_gmap[21] = 211;
  695.     IMP_gmap[22] = 251;
  696.     IMP_gmap[23] = 61232;
  697.     IMP_gmap[24] = 212;
  698.     IMP_gmap[25] = 137;
  699.     IMP_gmap[26] = 176;
  700.     IMP_gmap[27] = 161;
  701.     IMP_gmap[28] = 139;
  702.     IMP_gmap[29] = 133;
  703.     IMP_gmap[30] = 140;
  704.     IMP_gmap[31] = 61249;
  705.     IMP_gmap[32] = 8738;
  706.     IMP_gmap[34] = 186;
  707.     IMP_gmap[36] = 164;
  708.     IMP_gmap[39] = 185;
  709.     IMP_gmap[127] = 61286;
  710.  
  711.     /* for (i=1;i<127;i++) fprintf(stderr,"%d -> %d\n",i,IMP_gmap[i]); */
  712.  
  713.     for ( i=32;i<=127;i++) {
  714.         IMP_chmap [i] = i;
  715.     }
  716.     for ( i=128;i<=255;i++) {
  717.         IMP_chmap [i] = 128; /* first map all non printable chars to SPACE */
  718.     }
  719.  
  720.     IMP_chmap [161] = 27;
  721.     IMP_chmap [162] = 7;
  722.     IMP_chmap [163] = 8;
  723.     IMP_chmap [164] = 120;
  724.     IMP_chmap [165] = 10;
  725.     IMP_chmap [166] = 124;
  726.     IMP_chmap [167] = 11;
  727.     IMP_chmap [168] = 25;
  728.     IMP_chmap [169] = 21;
  729.     IMP_chmap [170] = 45;
  730.     IMP_chmap [171] = 12;
  731.     IMP_chmap [172] = 83;
  732.     IMP_chmap [173] = 45;
  733.     IMP_chmap [174] = 20;
  734.     IMP_chmap [175] = 126;
  735.     IMP_chmap [176] = 26;
  736.     IMP_chmap [177] = 12;
  737.     IMP_chmap [178] = 1;
  738.     IMP_chmap [179] = 2;
  739.     IMP_chmap [180] = 29;
  740.     IMP_chmap [181] = 52;
  741.     IMP_chmap [182] = 13;
  742.     IMP_chmap [183] = 5;
  743.     IMP_chmap [184] = 28;
  744.     IMP_chmap [185] = 3;
  745.     IMP_chmap [186] = 45;
  746.     IMP_chmap [187] = 16;
  747.     IMP_chmap [188] = 17;
  748.     IMP_chmap [189] = 18;
  749.     IMP_chmap [190] = 19;
  750.     IMP_chmap [191] = 15;
  751.     IMP_chmap [192] = 65;
  752.     IMP_chmap [193] = 65;
  753.     IMP_chmap [194] = 65;
  754.     IMP_chmap [195] = 65;
  755.     IMP_chmap [196] = 65;
  756.     IMP_chmap [197] = 3;
  757.     IMP_chmap [198] = 1;
  758.     IMP_chmap [199] = 67;
  759.     IMP_chmap [200] = 69;
  760.     IMP_chmap [201] = 69;
  761.     IMP_chmap [202] = 69;
  762.     IMP_chmap [203] = 69;
  763.     IMP_chmap [204] = 73;
  764.     IMP_chmap [205] = 73;
  765.     IMP_chmap [206] = 73;
  766.     IMP_chmap [207] = 73;
  767.     IMP_chmap [208] = 68;
  768.     IMP_chmap [209] = 78;
  769.     IMP_chmap [210] = 79;
  770.     IMP_chmap [211] = 79;
  771.     IMP_chmap [212] = 79;
  772.     IMP_chmap [213] = 79;
  773.     IMP_chmap [214] = 79;
  774.     IMP_chmap [215] = 13;
  775.     IMP_chmap [216] = 2;
  776.     IMP_chmap [217] = 85;
  777.     IMP_chmap [218] = 85;
  778.     IMP_chmap [219] = 85;
  779.     IMP_chmap [220] = 85;
  780.     IMP_chmap [221] = 89;
  781.     IMP_chmap [222] = 32;
  782.     IMP_chmap [223] = 22;
  783.     IMP_chmap [224] = 97;
  784.     IMP_chmap [225] = 97;
  785.     IMP_chmap [226] = 97;
  786.     IMP_chmap [227] = 97;
  787.     IMP_chmap [228] = 97;
  788.     IMP_chmap [229] = 6;
  789.     IMP_chmap [230] = 4;
  790.     IMP_chmap [231] = 99;
  791.     IMP_chmap [232] = 101;
  792.     IMP_chmap [233] = 101;
  793.     IMP_chmap [234] = 101;
  794.     IMP_chmap [235] = 101;
  795.     IMP_chmap [236] = 105;
  796.     IMP_chmap [237] = 105;
  797.     IMP_chmap [238] = 105;
  798.     IMP_chmap [239] = 105;
  799.     IMP_chmap [240] = 100;
  800.     IMP_chmap [241] = 110;
  801.     IMP_chmap [242] = 111;
  802.     IMP_chmap [243] = 111;
  803.     IMP_chmap [244] = 111;
  804.     IMP_chmap [245] = 111;
  805.     IMP_chmap [246] = 111;
  806.     IMP_chmap [247] = 10;
  807.     IMP_chmap [248] = 5;
  808.     IMP_chmap [249] = 117;
  809.     IMP_chmap [250] = 117;
  810.     IMP_chmap [251] = 117;
  811.     IMP_chmap [252] = 117;
  812.     IMP_chmap [253] = 121;
  813.     IMP_chmap [254] = 32;
  814.     IMP_chmap [255] = 121;
  815. }
  816.  
  817. void IMAGEN_createmap(name,map) 
  818. unsigned short *map; 
  819. int name; 
  820.     register int i,j; 
  821.     unsigned char s[4], *p; 
  822.  
  823.     p = s; 
  824.     *p++ = imP_CREATE_MAP; 
  825.     *p++ = name; 
  826.     j = 0; 
  827.     for (i=0;i<127;i++) { 
  828.         if ( map[i] ) j++; 
  829.     } 
  830.     *p = j; 
  831.     for (i=0;i<3;i++) putc(s[i],outfile); 
  832.  
  833.     s[3] = 1;
  834.     for (j=0;j<127;j++) { 
  835.         if ( map[j] ) { 
  836.             p = s; 
  837.             *p++ = j; 
  838.             *p++ = map[j] >> 8; 
  839.             *p   = map[j] & 255;
  840.             for (i=0;i<4;i++) putc(s[i],outfile); 
  841.         } 
  842.     } 
  843.  
  844. #endif /* TERM_BODY */
  845.  
  846. #ifdef TERM_TABLE
  847.  
  848. TERM_TABLE_START(imagen_driver)
  849.     "imagen", "Imagen laser printer",
  850.        IMAGEN_XMAX, IMAGEN_YMAX, IMAGEN_VCHAR, IMAGEN_HCHAR, 
  851.        IMAGEN_VTIC, IMAGEN_HTIC, IMAGEN_options, IMAGEN_init, IMAGEN_reset, 
  852.        IMAGEN_text, null_scale, IMAGEN_graphics, IMAGEN_move, 
  853.        IMAGEN_vector, IMAGEN_linetype, IMAGEN_put_text, IMAGEN_text_angle,
  854.        IMAGEN_justify_text, line_and_point, do_arrow, set_font_null
  855. TERM_TABLE_END(imagen_driver)
  856.  
  857. #undef LAST_TERM
  858. #define LAST_TERM imagen_driver
  859.  
  860. #endif /* TERM_TABLE */
  861. #endif /* TERM_PROTO_ONLY */
  862.  
  863. /*
  864.  * NAME: imagen
  865.  *
  866.  * OPTIONS: fontsize (default 12)
  867.  *        portrait|landscape (default landscape)
  868.  *        [horiz,vert] = window size, use with [], alternative to prt|lands
  869.  *
  870.  * SUPPORTS: Imagen laser printer
  871.  *
  872.  * Further Info: none
  873.  *
  874.  */
  875.